﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        campusnews cn = new campusnews();
        protected void Page_Load(object sender, EventArgs e)
        {
            btnupdate.Visible = false;
            if (!IsPostBack)
            {
                DataTable dt = cn.GetRecords(-99, "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            cn.newsid = -99;
            cn.news = tbnews.Text;
            cn.isdeleted = false;
            cn.SaveRecords();
            Response.Redirect("~/admin/CampusNews.aspx");
        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true;
            btninsert.Visible = false;
            DataTable dt = cn.GetRecords(Convert.ToInt64(e.CommandArgument), "", false, " and ");
            tbid.Text = dt.Rows[0]["newsid"].ToString();
            tbnews.Text = dt.Rows[0]["news"].ToString();
        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            DataTable dt=cn.GetRecords(Convert.ToInt64(e.CommandArgument),"",false," and ");
            cn.newsid = Convert.ToInt64(dt.Rows[0]["newsid"].ToString());
            cn.news = dt.Rows[0]["news"].ToString();
            cn.isdeleted = true;
            cn.SaveRecords();
            Response.Redirect("~/admin/CampusNews.aspx");

        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            cn.newsid = Convert.ToInt64(tbid.Text);
            cn.news = tbnews.Text;
            cn.isdeleted = false;
            cn.SaveRecords();
            Response.Redirect("~/admin/CampusNews.aspx");

        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
    }
}
